package com.assistant.controller;

import com.assistant.pojo.Items;
import com.assistant.pojo.ItemsPost;
import com.assistant.service.ItemsPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/ItemsPoster")
public class PostItemController {
    @Autowired
    private ItemsPostService itemsPostService;

    @PostMapping(value = "/insert", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public int insertPostItemsC(Items items, @RequestPart("files") MultipartFile[] files) {
        if (files != null) {
            items.setImg(itemsPostService.upLoadPic(files));//存入图片路径
        }
        return itemsPostService.insertPostItems(items);
    }

    @PostMapping(value = "/update")
    public int updateItemsMessageC(Items items, @RequestPart("files") MultipartFile[] files) {

        if (files != null) {
            items.setImg(itemsPostService.upLoadPic(files));//存入图片路径
        }
        return itemsPostService.updateItemsMessage(items);
    }


    @PostMapping(value = "/showMessageByXx")
    public List<ItemsPost> showItemMessageByXxxC(@RequestBody Map<String, String> map) {
        return itemsPostService.showItemsMessageByXxx(map);
    }


    @PutMapping("/cancle/{id}")
    public int cancelPostBookC(@PathVariable("id") Long id) {
        return itemsPostService.cancelPostItems(id);
    }

    /*
     * 删除一条记录
     * */
    @DeleteMapping("/deleteItems/{id}")
    public int deleteItems(@PathVariable("id") Integer id) {
        return itemsPostService.deleteItems(id);
    }

    /*
     * 审核通过闲置的记录
     * */
    @PutMapping("/updateStatus/{id}/{status}")
    public int updateStatus(@PathVariable("id") Integer id, @PathVariable("status") Integer status) {
        return itemsPostService.updateStatus(id, status);
    }

}
